/* eslint-disable no-unused-vars */
<template>
    <div class="home">
        <div class="header">
            <div class="address_map" @click="$router.push({name: 'address',params: {city: city}})">
                <i class="fa fa-map-marker"></i>
                <span>{{address}}</span>
                <i class="fa fa-sort-desc"></i>
            </div>
        </div>
          <div class="search_wrap" @click="$router.push('/search')">
              <div class="shop_search">
                <i class="fa fa-search"></i>
                搜索商家 商家名称
              </div>
        </div>
         <div id="container">
           <mt-swipe :auto="4000" class="swiper">
            <mt-swipe-item v-for="img in swipeImgs" :key="img.pirId">
              <img :src="img.pirName" alt>
            </mt-swipe-item>
           </mt-swipe>
           <!-- 分类 -->
           <mt-swipe :auto="0" class="entries">
        <mt-swipe-item v-for="(entry,i) in entries" :key="i" class="entry_wrap">
          <div class="foodentry" v-for="(item,index) in entry" :key="index">
            <div class="img_wrap">
              <img :src="item.cpir" alt>
            </div>
            <span>{{item.cname}}</span>
          </div>
        </mt-swipe-item>
      </mt-swipe>
         </div>
      <!-- 推荐商家 -->
    <div class="shoplist-title">推荐商家</div>
      <mt-loadmore
      :top-method="loadData"
      :bottom-method="loadMore"
      :bottom-all-loaded="allLoaded"
      :auto-fill="false"
      :bottomPullText="bottomPullText"
      ref="loadmore"
    >
    <div class="shopList">
      <IndexShop v-for="(item, index) in merchantList" :key="index" :data="item"/>
    </div>
     </mt-loadmore>
    </div>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import { Swipe, SwipeItem, Loadmore } from 'mint-ui'
import IndexShop from '../components/IndexShop'
export default {
  name: 'home',
  data () {
    return {
      queryInfo: {
        name: '',
        pageNum: 1,
        pageSize: 5
      },
      swipeImgs: [],
      entries: [],
      merchantList: [],
      allLoaded: false,
      bottomPullText: '上拉加载更多'
    }
  },
  computed: {
    address () {
      return this.$store.getters.address
    },
    city () {
      return (
        this.$store.getters.location.addressComponent.city ||
        this.$store.getters.location.addressComponent.province
      )
    }
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const { data: res } = await this.$http.get('picture')
      console.log(res.data)
      if (res.code !== 200) {
        return null
      }
      this.swipeImgs = res.data
      const { data: classify } = await this.$http.get('getClassifyList')
      console.log(classify.data)
      if (classify.code !== 200) {
        return null
      }
      this.entries = classify.data.entries
      const { data: merchat } = await this.$http.get('merchant', { params: this.queryInfo })
      console.log(merchat)
      if (merchat.code !== 200) {
        return null
      }
      this.merchantList = merchat.data.data
    },
    loadData () {
    },
    loadMore () {
    }
  },
  components: {
    // eslint-disable-next-line vue/no-unused-components
    IndexShop
  }
}
</script>

<style scoped>
.home {
  width: 100%;
  height: 100%;
  overflow: auto;
  box-sizing: border-box;
}
.header,
.search_wrap {
  background-color: #2f5f8bc7;
  padding: 10px 16px;
}
.header .address_map {
  color: #fff;
  font-weight: bold;
}
.address_map i {
  margin: 0 3px;
  font-size: 18px;
}
.address_map span {
  display: inline-block;
  width: 80%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.search_wrap .shop_search {
  /* margin-top: 10px; */
  background-color: #fff;
  padding: 10px 0;
  border-radius: 4px;
  text-align: center;
  color: #aaa;
}

.search_wrap {
  position: sticky;
  top: 0px;
  z-index: 999;
  box-sizing: border-box;
}
.swiper {
  height: 165px;
}
.swiper img {
  width: 100%;
  height: 180px;
}
#container{
  height: 300px;
}
.entries {
  background: #fff;
  height: 47.2vw;
  text-align: center;
  overflow: hidden;
}
.foodentry {
  width: 20%;
  float: left;
  position: relative;
  margin-top: 2.933333vw;
}
.foodentry .img_wrap {
  position: relative;
  display: inline-block;
  width: 12vw;
  height: 12vw;
}
.img_wrap img {
  width: 100%;
  height: 100%;
}
.foodentry span {
  display: block;
  color: #666;
  font-size: 0.32rem;
}
/* 推荐商家 */
.shoplist-title {
  display: flex;
  align-items: flex;
  justify-content: center;
  height: 9.6vw;
  line-height: 9.6vw;
  font-size: 16px;
  color: #333;
  background: #fff;
  margin-top: 55px;
}
.shoplist-title:after,
.shoplist-title:before {
  display: block;
  content: "一";
  width: 5.333333vw;
  height: 0.266667vw;
  color: #999;
}
.shoplist-title:before {
  margin-right: 3.466667vw;
}
.shoplist-title:after {
  margin-left: 3.466667vw;
}
</style>
